﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="FileManager.ascx.cs" Inherits="ERP.Modules.FileManager" %>
<script>
    var selectionChanged = function (dv,nodes) {
        var l = nodes.length;
        //#{PanelFile}.setTitle('Tập tin (' + l + ' tập tin được chọn)');
    };
</script>
<ext:Window 
    ID="WindowFileManager" 
    runat="server" 
    Title="Quản lý tập tin" 
    Icon="Application"
    Width="795" 
    Height="511"
    Border="False" 
    Collapsible="False"
    Region="Center"
    Resizable="False"
    Hidden="True"
    Modal="True"
    HideMode="Offsets"
    Plain="true"
    Layout="BorderLayout">
    <Items>
        <ext:Panel ID="PanelToolbarHeader"
            runat="server"
            Header="false"
            Region="North"
            Border="false"
            Layout="FitLayout">
            <Content>
                <ext:Toolbar runat="server" Dock="Top" Border="false">
                    <Items>
                        <ext:Button ID="btnCreateFolder" runat="server" Text="Tạo thư mục" Icon="FolderAdd">
                            <DirectEvents>
                                <Click OnEvent="btnCreateFolder_Click">
                                    <EventMask ShowMask="True" Msg="Đang tải"></EventMask>
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="btnDelFolder" runat="server" Text="Xoá" Icon="Reload">
                            <DirectEvents>
                                <Click OnEvent="btnDelFolder_Click">
                                    <EventMask ShowMask="True" Msg="Đang tải"></EventMask>
                                    <ExtraParams>
                                        <ext:Parameter Name="name" Value="btnDel"></ext:Parameter>
                                    </ExtraParams>
                                    <Confirmation ConfirmRequest="true"
                                        Title="Thông Báo" Message="Bạn có muốn xoá thư mục này không ?">
                                    </Confirmation>
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:FormPanel 
                            ID="BasicForm" 
                            runat="server"
                            Frame="True"
                            MarginSpec="0 8 0 0"
                            AutoHeight="true"
                            MonitorValid="true">
                            <Items>
                                <ext:FileUploadField 
                                    ID="FileUploadPanel" 
                                    runat="server" 
                                    EmptyText="Chọn tập tin"
                                    ButtonText=""
                                    MarginSpec="0 8 0 0"
                                    Icon="Attach">
                                </ext:FileUploadField>
                            </Items>
                        </ext:FormPanel>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="btnUpload" runat="server" Text="Tải lên">
                            <DirectEvents>
                                <Click 
                                    OnEvent="btnUpload_Click"
                                    Before="if (!#{BasicForm}.getForm().isValid()) { return false; } 
                                        Ext.Msg.wait('Đang tải tập tin...', 'Đang tải');"
                                
                                    Failure="Ext.Msg.show({ 
                                        title   : 'Lỗi', 
                                        msg     : 'Có lỗi xảy ra trong quá trình tải lên.Hoặc dung lượng tập tin quá lớn', 
                                        minWidth: 200, 
                                        modal   : true, 
                                        icon    : Ext.Msg.ERROR, 
                                        buttons : Ext.Msg.OK 
                                    });">
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="btnRefreshFolder" runat="server" Text="Tải lại" Icon="Reload">
                            <DirectEvents>
                                <Click OnEvent="btnRefreshFolder_Click">
                                        <EventMask ShowMask="True" Msg="Đang tải"></EventMask>
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </Content>
        </ext:Panel>
        <ext:Panel ID="PanelFolder" 
            runat="server" 
            Region="West" 
            Collapsible="False" 
            MinWidth="175" 
            Split="False" 
            Width="175" 
            Title="Thư mục">
            <Content>
                <ext:GridPanel
                    ID="grFolder"
                    Cls="grid-double"
                    runat="server"
                    EnableColumnMove="False"
                    Border="False">
                    <Store>
                        <ext:Store
                            ID="StoreFolder"
                            runat="server"
                            OnReadData="StoreFolder_RefreshData"
                            PageSize="20">
                            <Model>
                                <ext:Model ID="ModelFoder" runat="server" IDProperty="Name">
                                    <Fields>
                                        <ext:ModelField Name="Name" Type="String" />
                                    </Fields>
                                </ext:Model>
                            </Model>
                        </ext:Store>
                    </Store>
                    <ColumnModel runat="server">
                        <Columns>
                            <ext:Column runat="server" Text="Tên thư mục" Width="109" DataIndex="Name" Flex="1"></ext:Column>
                        </Columns>
                    </ColumnModel>
                    <SelectionModel>
                        <ext:CheckboxSelectionModel runat="server" Mode="Multi" />
                    </SelectionModel>
                    <DirectEvents>
                        <ItemDblClick OnEvent="PathDb_Click">
                            <ExtraParams>
                                <ext:Parameter Name="Name" Value="record.data.Name" Mode="Raw" />
                            </ExtraParams>
                            <EventMask ShowMask="true" Msg="Đang tải..." />
                        </ItemDblClick>
                    </DirectEvents>
                </ext:GridPanel>
            </Content>
        </ext:Panel>
        <ext:Panel 
            ID="PanelFile"
            Region="Center"
            Cls="images-view"
            runat="server" 
            Title="Tập tin (0 tập tin được chọn)"
            BodyPadding="6">
            <Items>
                <ext:DataView
                ID="ImageView"
                runat="server"
                MultiSelect="False"
                OverItemCls="x-item-over"
                ItemSelector="div.thumb-wrap"
                EmptyText="Không có tập tin được hiễn thị"
                TrackOver="true">
                <Store>
                    <ext:Store ID="StoreFile" runat="server" PageSize="20" OnReadData="StoreFile_RefreshData">
                        <Model>
                            <ext:Model runat="server" IDProperty="name">
                                <Fields>
                                    <ext:ModelField Name="name" />
                                    <ext:ModelField Name="url" />      
                                    <ext:ModelField Name="size" Type="Int" />
                                    <ext:ModelField Name="lastmod" Type="Date" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <Tpl runat="server">
                    <Html>
						<tpl for=".">
							<div class="thumb-wrap" id="{name}">
								<div class="thumb">
									<img src="{url}" title="{name}"></img>
								</div>
								<span class="x-editable" style="color: red">{shortName}</span>
							</div>
						</tpl>
						<div style="clear: both !important"></div>
					</Html>
                </Tpl>
                <PrepareData Fn="prepareData" />
                <Listeners>
                    <SelectionChange Fn="selectionChanged" /> 
                </Listeners>
                </ext:DataView>
                <ext:Hidden runat="server" ID="hdPath"></ext:Hidden>
                <ext:Hidden runat="server" ID="lbFileName" ></ext:Hidden>
            </Items>
            <DockedItems>
                <ext:Toolbar runat="server" Dock="Bottom" AnchorHorizontal="100%">
                    <Items>
                        <ext:PagingToolbar runat="server" StoreID="StoreFile" BeforePageText="Trang" AfterPageText="của {0}" LastText="Cuối" NextText="Kế tiếp" PrevText="Trở lại" FirstText="Đầu" RefreshText="Làm tươi" DisplayInfo="true" DisplayMsg="Trang {0} - {1} của {2}" />
                        <ext:ToolbarSeparator />
                        <ext:Button ID="btnSubmitSelect" runat="server" Text="Chọn">
                            <DirectEvents>
                                <Click OnEvent="btnSubmitSelect_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="btnDelFile" runat="server" Text="Xoá">
                            <DirectEvents>
                                <Click OnEvent="btnDelFile_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                    <ExtraParams>
                                        <ext:Parameter Name="name" Value="btnDelFile"></ext:Parameter>
                                    </ExtraParams>
                                    <Confirmation ConfirmRequest="true"
                                        Title="Thông Báo" Message="Bạn có muốn xoá tập tin này không ?">
                                    </Confirmation>
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="btnClear" runat="server" Text="Bỏ chọn">
                            <DirectEvents>
                                <Click OnEvent="btnClear_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="btnClose" runat="server" Text="Đóng">
                            <DirectEvents>
                                <Click OnEvent="btnClose_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </DockedItems>
        </ext:Panel>
    </Items>
</ext:Window>
<ext:Window 
    ID="WindowCreateFolder" 
    runat="server" 
    Closable="false"
    Resizable="false"
    Height="150" 
    Icon="Lock" 
    Title="Login"
    Draggable="false"
    Hidden="True"
    Width="350"
    Modal="True"
    Border="false"
    BodyPadding="5"
    HideMode="Offsets"
    Layout="FormLayout">
    <Items>
        <ext:TextField 
            ID="txtPath" 
            runat="server"     
            FieldLabel="Đường dẩn:" 
            ReadOnly="True" FieldCls="readonly"
            EmptyText="Đường dẩn">
        </ext:TextField>

        <ext:TextField 
            ID="txtFolderName" 
            runat="server"     
            FieldLabel="Tên thư mục:" 
            EmptyText="Nhập vào tên thư mục">
        </ext:TextField>
    </Items>
    <Buttons>
        <ext:Button ID="btnCreate" runat="server" Text="Tạo thư mục" Icon="Disk">
            <DirectEvents>
                <Click OnEvent="btnCreate_Click">
                    <EventMask ShowMask="true" Msg="Đang tải..." />
                </Click>
            </DirectEvents>
        </ext:Button>
        <ext:Button ID="btnCancel" runat="server" Text="Bỏ qua" Icon="Decline">
            <DirectEvents>
                <Click OnEvent="btnCancel_Click">
                    <EventMask ShowMask="true" Msg="Đang tải..." />
                </Click>
            </DirectEvents>
        </ext:Button>
    </Buttons>
</ext:Window>